Skip to content

Fix console crash and console key input#1880

Open
VReaperV wants to merge 2 commits intoDaemonEngine:masterfrom
VReaperV:fix-console
Open

Fix console crash and console key input#1880
VReaperV wants to merge 2 commits intoDaemonEngine:masterfrom
VReaperV:fix-console

Conversation

@VReaperV
Copy link
Contributor

  • Fixes a crash in auto-complete (start typing a command, move cursor back to start of the line, press tab)
  • Fixes console key sometimes being caught in the console input sometimes. This one's a bit difficult to reproduce, I've mainly seen it happen when tabbing out before/during a map change with console open, then tabbing back in after the map loads and opening the console again. Also reproducible by setting input method to UK English in Windows 11, though it has a different underlying cause

return Key::NONE;
}

std::string KeyToStringUnprefixed( Key key ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, what is the point of forming a string with words like ESCAPE, 0x63 etc.?

* in a separate execution of IN_ProcessEvents()
* The key character can also be anywhere in the text
* This might be an SDL bug */
text.erase(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would break the feature where you can hold ALT to type a character that would otherwise be a console key (works on some Linux environments)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that handled in SDL_EVENT_KEY_DOWN()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is where the ALT exemption is initially applied. But IIUC this new third level of console key filtering has no condition to check that, so such characters would be filtered out.

int argNum = args.Argc() - 1;
std::string prefix;
if (!args.Argc() || Str::cisspace(GetText()[GetCursorPos() - 1])) {
if (!args.Argc() || !GetCursorPos() || Str::cisspace(GetText()[GetCursorPos() - 1])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way things initially go wrong is with the subtraction underflow in std::string commandText = Str::UTF32To8(GetText().substr(1, GetCursorPos() - 1));. Would be nicer to return before that

@slipher
Copy link
Member

slipher commented Mar 9, 2026

For future reference, the Windows 11 keyboard layout where the console key issue always happens is "United Kingdom Extended" which has a ` dead key.

There are other layouts which have an (Right)Alt + ` dead key combination; alt-tabbing in those could lead to accidentally triggering the dead key (and hence the bug) if pressing the console key while Alt is still held. I guess this never happens to me only because I always use left Alt for alt-tabbing.

Filtering out the console key itself won't get all possible cases of junk caused by dead keys. For example if a ` dead key is queued up when you open the console and then the first letter you type is e you will get è. Maybe what we would need to do is reset the text input state machine, if possible. Perhaps by turning off and on text input in SDL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants